//
//  LLSignViewController.m
//  LoveLove
//
//  Created by 达迩科技 on 2019/4/12.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "LLSignViewController.h"
#import "CalenderView.h"
#import "LLSignInView.h"

@interface LLSignViewController ()<UINavigationControllerDelegate,LLSignInViewDelete>
@property (nonatomic, strong) CalenderView *calenderView;
@property (nonatomic, strong) LLSignInView *signInView;
@property (nonatomic, strong) UIImageView *image1;
@property (nonatomic, strong) UIImageView *image2;
@end

@implementation LLSignViewController

- (void)viewWillAppear:(BOOL)animated {
    [[IQKeyboardManager sharedManager] setEnable:NO];
    [super viewWillAppear:animated];
    [SVProgressHUD dismiss];
    self.navigationController.delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    //TODO: 页面Disappear 启用
    [[IQKeyboardManager sharedManager] setEnable:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.titleView removeFromSuperview];
    UIImageView *bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, LLScreenWidth, 280)];
    bgImage.image = [UIImage imageNamed:@"图层 4 拷贝 2"];
    [self.view addSubview:bgImage];
    
    UILabel *titleLabel = [LLInitBaseViewTool labelWithText:@"每日签到" textColor:LLColorRGB(255) font:18 textAlignment:NSTextAlignmentCenter];
    titleLabel.frame = CGRectMake(LLScreenWidth/2-100, 58, 200, 18);
    [bgImage addSubview:titleLabel];
    
    LLButton *leftButton = [LLInitBaseViewTool buttonWithTitle:nil image:@"左箭头" titleColor:nil font:0];
    leftButton.frame = CGRectMake(20, 58, 28, 18);
    [leftButton addTarget:self action:@selector(didButtonWithleftButton11) forControlEvents:UIControlEventTouchUpInside];
    leftButton.userInteractionEnabled = YES;
    [self.view addSubview:leftButton];
    
    self.signinButton = [LLInitBaseViewTool buttonWithTitle:nil image:@"矩形 4 拷贝 10" titleColor:nil font:0];
    self.signinButton.frame = CGRectMake(bgImage.width/2-131/2, bgImage.height-131-49, 131, 131);
    [self.signinButton addTarget:self action:@selector(didButtonWithSignin) forControlEvents:UIControlEventTouchUpInside];
    self.signinButton.userInteractionEnabled = YES;
    [self.view addSubview:self.signinButton];
    
    self.calenderView = [[CalenderView alloc]initWithFrame:CGRectMake(10, 300, LLScreenWidth- 20, LLScreenHeight-320)];
    self.calenderView.selectDate = [NSMutableArray arrayWithCapacity:0];
    [self.calenderView.selectDate addObject:@"2019-04-02"];
    [self.calenderView.selectDate addObject:@"2019-04-07"];
    [self.calenderView.selectDate addObject:@"2019-04-08"];
    [self.view addSubview:self.calenderView];
    
    self.image1 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 272, 10, 38)];
    self.image1.image = [UIImage imageNamed:@"close"];
    [self.view addSubview:self.image1];
    
    self.image2 = [[UIImageView alloc] initWithFrame:CGRectMake(LLScreenWidth-60, 272, 10, 38)];
    self.image2.image = [UIImage imageNamed:@"close"];
    [self.view addSubview:self.image2];
    
    // Do any additional setup after loading the view.
}


- (void)didButtonWithSignin{
    [self signInView];
    self.signInView.hidden = NO;
    self.signInView.daysLabel.text = @"第3天";
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:self.signInView.daysLabel.text];
    NSRange range1 = [self.signInView.daysLabel.text rangeOfString:@"3"];
    [AttributedStr addAttribute:NSFontAttributeName value:LLRegularFont(39) range:range1];
    self.signInView.daysLabel.attributedText = AttributedStr;
}

- (void)didSelectButton:(LLSignInView *)view{
    self.signInView.hidden = YES;;
    [self.calenderView removeFromSuperview];
    [self.signinButton setImage:[UIImage imageNamed:@"课程图片"] forState:0];
    self.signinButton.userInteractionEnabled = NO;
    self.calenderView = [[CalenderView alloc]initWithFrame:CGRectMake(10, 300, LLScreenWidth- 20, LLScreenHeight-320)];
    self.calenderView.selectDate = [NSMutableArray arrayWithCapacity:0];
    [self.calenderView.selectDate addObject:@"2019-04-02"];
    [self.calenderView.selectDate addObject:@"2019-04-07"];
    [self.calenderView.selectDate addObject:@"2019-04-08"];
    NSString *date = [NSString getCurrentTime:@"yyyy-MM-dd"];
    [self.calenderView.selectDate addObject:date];
    [self.view addSubview:self.calenderView];

    [self.view addSubview:self.image1];
    [self.view addSubview:self.image2];
}
- (void)didButtonWithleftButton11{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark ---- dealloc
- (void)dealloc {
    [LLNotificationCenter removeObserver:self];
}

#pragma mark - UINavigationControllerDelegate
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}

-(LLSignInView *)signInView{
    if (_signInView == nil) {
        _signInView = [[LLSignInView alloc] initWithFrame:self.view.bounds];
        _signInView.hidden = YES;
        _signInView.delegate = self;
        [self.view addSubview:_signInView];
    }
    return _signInView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
